package com.waidi.clothespad.fragment;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Fragment;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Bitmap;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.waidi.clothespad.ClothesMainActivity;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.graphics.drawable.ClipDrawable;
import android.graphics.drawable.ColorDrawable;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.text.Editable;
import android.text.InputType;
import android.text.TextPaint;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;

import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.TranslateAnimation;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.graphics.drawable.AnimationDrawable;

import com.waidi.clothespad.adapter.ViewPageAdapter;
import com.waidi.clothespad.common.Config;
import com.waidi.clothespad.common.DpsInterface;
import com.waidi.clothespad.common.DpsOrderInfo;
import com.waidi.clothespad.common.HttpGetThread;
import com.waidi.clothespad.common.MessageToUi;
import com.waidi.clothespad.common.MyToast;
import com.waidi.clothespad.common.RealData;

import com.waidi.clothespad.R;
import com.waidi.clothespad.common.RfidData;
import com.waidi.clothespad.common.StyeNumInfo;
import com.waidi.clothespad.common.WorkerInfo;
import com.waidi.clothespad.imgview.PhotoView;
import com.waidi.clothespad.mqttclient.MyMqttClient;
import com.waidi.clothespad.ui.MyImageView;
import com.waidi.clothespad.ui.QrCodeBoundDialog;
import com.waidi.clothespad.ui.QrCodeSwitchDialog;
import com.waidi.clothespad.ui.StyleNumSizeInfoDialog;
import com.waidi.clothespad.ui.WorkerinfoDialog;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import android.graphics.Matrix;
import android.util.DisplayMetrics;
import android.graphics.PointF;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.FloatMath;
import android.view.MotionEvent;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.Toast;
import android.widget.ViewSwitcher;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;

import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import  java.lang.reflect.Field;
import java.net.DatagramPacket;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.net.URLEncoder;
import java.security.acl.LastOwnerException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by Administrator on 2017/4/26.
 */

public class FragShishishuju extends Fragment {
    private static final String TAG = "shishishuju: ";
    @BindView(R.id.iv_call)
    ImageView ivCall;
    @BindView(R.id.ll_worker_more)
    LinearLayout ll_worker_more;
    @BindView(R.id.tv_log_statue)
    TextView tv_log_statue;

    @BindView(R.id.iv_bantu)
    MyImageView image_gy;
    //ImageView image_gy;

//顶部显示
    @BindView(R.id.tv_order_id)
    TextSwitcher Tv_order_id;

    @BindView(R.id.tv_order_tag)
    TextView Tv_order_tag;

    @BindView(R.id.tv_style_id)
    TextSwitcher Tv_style_id;


    @BindView(R.id.tv_style_name)
    TextSwitcher Tv_style_name;



    @BindView(R.id.tv_order_num)
    TextSwitcher Tv_order_num;


    @BindView(R.id.tv_custom_name)
    TextSwitcher Tv_custom_name;


    @BindView(R.id.tv_order_agree_date)
    TextSwitcher Tv_order_agree_date;



    @BindView(R.id.style_colour)
    TextView Tv_style_colour;

    @BindView(R.id.tv_main_material)
    TextView Tv_main_material;
    @BindView(R.id.style_size)
    TextView Tv_style_size;

    @BindView(R.id.ic_down_up)
    ImageView Img_down_up;

    @BindView(R.id.linearlayout_size)
    LinearLayout linearlayout_size;


    @BindView(R.id.ivstyle_more)
    TextView ivstyle_more;

    @BindView(R.id.tv_hg_finish_num)
    TextSwitcher Tv_hg_finish_num;


    @BindView(R.id.opera_desc)
    TextView Tv_opera_desc;

    @BindView(R.id.hangerid)
    TextView Tv_hangerid;

    @BindView(R.id.standard_time)
    TextView Tv_standard_time;


    @BindView(R.id.progress_bar_h)
    ProgressBar progress_bar;

    @BindView(R.id.worke_time)
    TextView Tv_worke_time;




    private int ic_down_up_flag = 0;


    Unbinder unbinder;
    private View view;
    public Context context;
    PopupWindow popupWindow;
    LayoutInflater inflater;
    public ShiShiSuJuHandler handler;
    public Handler Activityhandler;
    public TimerHandler timerhandler;;

    public int calltype = 0;
    public String deal_result = "";
    public boolean call_flag = false;
    public String gy_image_name;
    public boolean coon = false;
    public boolean onDetach = false;
    public boolean iscalled = false;
    private int resume = 0;
    public RealData realData = null;
    public File image_dir;
    public  ClothesMainActivity.CalThread calThread;
    private AnimationDrawable animationDrawable;
    private WorkerinfoDialog workerinfoDialog=null;
    private StyleNumSizeInfoDialog styleNumSizeInfoDialog = null;
    private boolean isLogin = false;
    private static String lastCache;
    private static int lastCacheNo=0;
    private static String lastHangerId="";


    private static String lastProcessCache;
    private static int lastProcessCacheNo=0;

    private static String lastProcessPicUrlCache;
    private static String lastProcessPicUrlCacheTmp;
    private static int lastProcessPicUrlCacheNo=0;
    public QrCodeBoundDialog qrCodeBoundDialog = null;
    private QrCodeSwitchDialog qrCodeSwitchDialog =null;

    //viewpager
    private ViewPager viewPager;
    private LinearLayout ll_point_container;
    private int[] imageResIds;
    private ArrayList<ImageView> imageViewList;
    private ArrayList<String> contentList;
    private int previousSelectedPosition = 0;

    private ViewPageAdapter viewPageAdapter = null;
    public Drawable resource;
    private ArrayList<Drawable> drawableList;
    private ArrayList<String> urlList;
    private DisplayImageOptions options;


    private AnimationSet InAnimationSet;
    private AnimationSet OutAnimationSet;

    private AnimationSet InAnimationSet1;
    private AnimationSet OutAnimationSet1;

    private AnimationSet InAnimationSet2;
    private AnimationSet OutAnimationSet2;

    private AnimationSet InAnimationSet3;
    private AnimationSet OutAnimationSet3;

    private AnimationSet InAnimationSet4;
    private AnimationSet OutAnimationSet4;

    private AnimationSet InAnimationSet5;
    private AnimationSet OutAnimationSet5;

    private AnimationSet InAnimationSet6;
    private AnimationSet OutAnimationSet6;

    private Handler handlerqr = new Handler();
    private Runnable runnable;



    public FragShishishuju() {
        handler = new ShiShiSuJuHandler();
        timerhandler = new TimerHandler();

        Log.i(TAG,"FragShishishuju--->handler");
        realData = new RealData();
        iscalled = false;
        call_flag = false;
        isLogin = false;

    }


    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        System.out.println("LeftFragment--->onCreate");
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        view = inflater.inflate(R.layout.frag_shishishuju_new, container, false);
        unbinder = ButterKnife.bind(this, view);
        onDetach = false;
        lastCache="";

        lastProcessCache = "";
        lastProcessPicUrlCache="";
        lastProcessPicUrlCacheTmp = "";

        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        context = getActivity();
        initParams();
        initElem();
        init_workerinfo();
        init_viewpager();
        create_animation();

    }
    @OnClick(R.id.tv_order_tag)
    public void update_order_info()
    {
        RfidData tmp = new RfidData();
        tmp.type = "02";
        tmp.id = "";
        tmp.data="";
        Config.readWriteLock.writeLock().lock();
        Config.hgrfiddataqueue.offer(tmp);
        Config.readWriteLock.writeLock().unlock();
        lastCache = "null";
        lastCacheNo = 0;

        lastProcessCache = "";
        lastProcessCacheNo = 0;

        lastProcessPicUrlCache="";
        lastProcessPicUrlCacheNo= 0;
        lastProcessPicUrlCacheTmp="";


    }
    @OnClick(R.id.ic_down_up)
    public void linearlayout_expand()
    {
        if(DpsOrderInfo.typeSizeNameInfo.size()>1) {
            if(ic_down_up_flag==1)
            {
                Tv_style_size.setHeight(Tv_style_size.getLineHeight() * 1);
                Tv_style_size.setText(DpsOrderInfo.typeSizeNameInfo.get(0).name + "#" + DpsOrderInfo.typeSizeNameInfo.get(0).qty);
                Img_down_up.setImageResource(R.mipmap.ic_down);
                ic_down_up_flag = 0;
                return;
            }
            ic_down_up_flag = 1;
            Log.i(TAG, "=========");
            String style_size = "";
            int k = 1;
            for (k = 1; k < DpsOrderInfo.typeSizeNameInfo.size() + 1; k++) {
                style_size = style_size + DpsOrderInfo.typeSizeNameInfo.get(k - 1).name +
                        "#" + DpsOrderInfo.typeSizeNameInfo.get(k - 1).qty + "\n";
            }
            Tv_style_size.setHeight(Tv_style_size.getLineHeight() * k);
            Tv_style_size.setText(style_size);
            Img_down_up.setImageResource(R.mipmap.ic_up);
/*            Tv_style_size.post(new Runnable() {
                @Override
                public void run() {
                    Img_down_up.setImageResource(R.mipmap.ic_up);
                }
            });*/
        }

    }

    public void initParams() {
        inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View contentview = inflater.inflate(R.layout.layout_pop_call, null);
        contentview.setFocusable(true); // 这个很重要
        contentview.setFocusableInTouchMode(true);
        initContentview(contentview);
        popupWindow = new PopupWindow(contentview, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        popupWindow.setFocusable(true);
        popupWindow.setBackgroundDrawable(new ColorDrawable(0x00000000));

        //FlushRealData();
    }


    Timer timer = new Timer();
    TimerTask task =
            new TimerTask() {
        @Override
        public void run()
        {
            if (onDetach == false)
            {

                Message message = new Message();
                message.arg1 = 1;
                timerhandler.sendMessage(message);
                //  Log.i(TAG,"主Activity 定时器工作。。。");
            }
        }
    };
    public void create_animation()
    {

        AlphaAnimation alphaAnimation;
        TranslateAnimation translateAnimation;
        InAnimationSet = new AnimationSet(true);
        OutAnimationSet = new AnimationSet(true);

        InAnimationSet1 = new AnimationSet(true);
        OutAnimationSet1 = new AnimationSet(true);

        InAnimationSet2 = new AnimationSet(true);
        OutAnimationSet2 = new AnimationSet(true);


        InAnimationSet3 = new AnimationSet(true);
        OutAnimationSet3 = new AnimationSet(true);

        InAnimationSet4 = new AnimationSet(true);
        OutAnimationSet4 = new AnimationSet(true);

        InAnimationSet5 = new AnimationSet(true);
        OutAnimationSet5 = new AnimationSet(true);

        InAnimationSet6 = new AnimationSet(true);
        OutAnimationSet6 = new AnimationSet(true);


        Tv_order_id.setFactory(new ViewSwitcher.ViewFactory() {
            @Override
            public View makeView() {
                return new TextView(context);
            }
        });

        Tv_style_id.setFactory(new ViewSwitcher.ViewFactory() {
            @Override
            public View makeView() {
                return new TextView(context);
            }
        });
        Tv_style_name.setFactory(new ViewSwitcher.ViewFactory() {
            @Override
            public View makeView() {
                return new TextView(context);
            }
        });
        Tv_order_num.setFactory(new ViewSwitcher.ViewFactory() {
            @Override
            public View makeView() {
                return new TextView(context);
            }
        });
        Tv_custom_name.setFactory(new ViewSwitcher.ViewFactory() {
            @Override
            public View makeView() {
                return new TextView(context);
            }
        });
        Tv_order_agree_date.setFactory(new ViewSwitcher.ViewFactory() {
            @Override
            public View makeView() {
                return new TextView(context);
            }
        });



        int h = Tv_order_id.getHeight();
        if (h <= 0) {
            Tv_order_id.measure(0,0);
            h = Tv_order_id.getMeasuredHeight();
        }

        Tv_hg_finish_num.setFactory(new ViewSwitcher.ViewFactory() {
            @Override
            public View makeView() {
                TextView t = new TextView(context);
                t.setTextColor(Color.parseColor("#ffff4444"));
                t.setTextSize(28);
                t.setGravity(Gravity.CENTER);
                TextPaint tp = t.getPaint();
                tp.setFakeBoldText(true);
                return  t;
            }
        });



        alphaAnimation = new AlphaAnimation(0,1);
        translateAnimation = new TranslateAnimation(Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 0,
                Animation.ABSOLUTE, h, Animation.ABSOLUTE, 0);
        InAnimationSet.addAnimation(alphaAnimation);
        InAnimationSet.addAnimation(translateAnimation);
        InAnimationSet.setDuration(1000);

        InAnimationSet1.addAnimation(alphaAnimation);
        InAnimationSet1.addAnimation(translateAnimation);
        InAnimationSet1.setDuration(1000);

        InAnimationSet2.addAnimation(alphaAnimation);
        InAnimationSet2.addAnimation(translateAnimation);
        InAnimationSet2.setDuration(1000);

        InAnimationSet3.addAnimation(alphaAnimation);
        InAnimationSet3.addAnimation(translateAnimation);
        InAnimationSet3.setDuration(1000);

        InAnimationSet4.addAnimation(alphaAnimation);
        InAnimationSet4.addAnimation(translateAnimation);
        InAnimationSet4.setDuration(1000);

        InAnimationSet5.addAnimation(alphaAnimation);
        InAnimationSet5.addAnimation(translateAnimation);
        InAnimationSet5.setDuration(1000);


        InAnimationSet6.addAnimation(alphaAnimation);
        InAnimationSet6.addAnimation(translateAnimation);
        InAnimationSet6.setDuration(1500);



        alphaAnimation = new AlphaAnimation(1,0);
        translateAnimation = new TranslateAnimation(Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 0,
                Animation.ABSOLUTE, 0, Animation.ABSOLUTE, -h);
        OutAnimationSet.addAnimation(alphaAnimation);
        OutAnimationSet.addAnimation(translateAnimation);
        OutAnimationSet.setDuration(1000);

        OutAnimationSet1.addAnimation(alphaAnimation);
        OutAnimationSet1.addAnimation(translateAnimation);
        OutAnimationSet1.setDuration(1000);

        OutAnimationSet2.addAnimation(alphaAnimation);
        OutAnimationSet2.addAnimation(translateAnimation);
        OutAnimationSet2.setDuration(1000);

        OutAnimationSet3.addAnimation(alphaAnimation);
        OutAnimationSet3.addAnimation(translateAnimation);
        OutAnimationSet3.setDuration(1000);

        OutAnimationSet4.addAnimation(alphaAnimation);
        OutAnimationSet4.addAnimation(translateAnimation);
        OutAnimationSet4.setDuration(1000);

        OutAnimationSet5.addAnimation(alphaAnimation);
        OutAnimationSet5.addAnimation(translateAnimation);
        OutAnimationSet5.setDuration(1000);

        //
        OutAnimationSet6.addAnimation(alphaAnimation);
        OutAnimationSet6.addAnimation(translateAnimation);
        OutAnimationSet6.setDuration(1500);

    }

   // private int  resource =0 ;


    public void init_viewpager()
    {
        init_imageLoader();
        // 默认图片资源id数组
        imageResIds = new int[]{R.drawable.default_a0, R.drawable.default_a1, R.drawable.default_a2, R.drawable.d, R.drawable.e};
        // 初始化要展示的5个ImageView
        imageViewList = new ArrayList<ImageView>();

        viewPager = (ViewPager) view.findViewById(R.id.viewpager);
        ll_point_container = (LinearLayout) view.findViewById(R.id.ll_point_container);


        View pointView;
        LinearLayout.LayoutParams layoutParams;

        for ( int i = 0; i < imageResIds.length-2; i++) {
            // 初始化要显示的图片对象
            final ImageView imageView;
            imageView = new ImageView(context);
            //imageView.setBackgroundResource(imageResIds[i]);
            imageView.setImageResource(imageResIds[i]);

            Log.i(TAG,"1# "+Integer.toString(imageResIds[i]));

          /*  点击放大 imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    initImageView();
                }
            });*/

            imageViewList.add(imageView);
            // 加小白点, 指示器
            pointView = new View(context);
            pointView.setBackgroundResource(R.drawable.selector_bg_point);
            layoutParams = new LinearLayout.LayoutParams(10, 10);
            if (i != 0)
                layoutParams.leftMargin = 10;
            // 设置默认所有都不可用
            pointView.setEnabled(false);
            ll_point_container.addView(pointView, layoutParams);
        }

        initAdapter();

        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener()
        {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }
            @Override
            public void onPageSelected(int position) {
                if(imageViewList.size()<=0)
                    return;

                // 新的条目被选中时调用
                int newPosition = position % imageViewList.size();
                Log.i(TAG,"onPageSelected: " + position+" size: "+imageViewList.size()+" # "+newPosition);

               // System.out.println("onPageSelected: " + position+" size: "+imageViewList.size()+" # "+newPosition);
                resource = imageViewList.get(newPosition).getDrawable();

               // Log.i(TAG,"2# "+Integer.toString(resource));

                //                //设置文本
/*                if(contentList.size()>newPosition) {
                   // tv_desc.setText(contentList.get(newPosition));
                    System.out.println("onPageSelected-2: " + contentList.get(newPosition));
                }*/

                //把之前的禁用, 把最新的启用, 更新指示器
                ll_point_container.getChildAt(previousSelectedPosition).setEnabled(false);
                ll_point_container.getChildAt(newPosition).setEnabled(true);
                //记录之前的位置
                previousSelectedPosition  = newPosition;
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    private void initImageView() {
        final WindowManager windowManager = ((Activity) context).getWindowManager();
        final RelativeLayout relativeLayout = new RelativeLayout(context);
        WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();

        DisplayMetrics metric = new DisplayMetrics();
        windowManager.getDefaultDisplay().getMetrics(metric);
     /*   mScreenWidth = metric.widthPixels;
        mScreenHeight = metric.heightPixels;
*/
        layoutParams.width = metric.widthPixels;
        layoutParams.height = metric.heightPixels;
        //FLAG_LAYOUT_IN_SCREEN
        layoutParams.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN;
       // layoutParams.format = PixelFormat.RGBA_8888;//让背景透明，放大过程可以看到当前界面
        layoutParams.verticalMargin = 0;
        windowManager.addView(relativeLayout, layoutParams);


        final PhotoView animationIV = new PhotoView(context);

        animationIV.setScaleType(ImageView.ScaleType.FIT_CENTER);
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        relativeLayout.addView(animationIV, params);
        relativeLayout.setFocusableInTouchMode(true);
        //animationIV.setImageResource(resource);
        animationIV.setImageDrawable(resource);

        //Picasso.with(getContext()).load(imageId).into(animationIV);
        animationIV.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                windowManager.removeView(relativeLayout);
            }
        });
        relativeLayout.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK) {
                    if (null != windowManager && null != relativeLayout) {
                        windowManager.removeView(relativeLayout);
                    }
                    return true;
                }
                return false;
            }
        });
    }

    private  void init_imageLoader()
    {
        options = new DisplayImageOptions.Builder()
                .cacheInMemory(false)
                .cacheOnDisk(false)
                .showImageForEmptyUri(R.drawable.houdao_default)
                .showImageOnLoading(R.drawable.animation3)
                .showImageOnFail(R.drawable.image_err)
                .imageScaleType(ImageScaleType.IN_SAMPLE_INT)
/*                .displayer(new RoundedBitmapDisplayer(50))
                .displayer(new FadeInBitmapDisplayer(100))*/
                .bitmapConfig(Bitmap.Config.RGB_565).build();
        //图片加载器ImageLoader
        //创建默认的ImageLoader配置参数

        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
                context)
                .memoryCacheExtraOptions(480, 800)// 缓存在内存的图片的宽和高度
                .memoryCacheSize(2 * 1024 * 1024) //缓存到内存的最大数据
                .defaultDisplayImageOptions(options).  //上面的options对象，一些属性配置
                build()
                ;
        //Initialize ImageLoader with configuration.
        ImageLoader.getInstance().init(config);
        drawableList = new ArrayList<Drawable>();
        urlList = new ArrayList<String>();
    }

    private void addUrlIamgePage(String url)
    {
        ImageView imageView;
        View pointView;
        LinearLayout.LayoutParams layoutParams;
        //初始化要显示的图片对象
        imageView = new ImageView(context);
        try
        {
            ImageLoader.getInstance().clearDiskCache();//清除磁盘缓存
            ImageLoader.getInstance().clearMemoryCache();//清除内存缓存

            ImageLoader.getInstance().displayImage(url, imageView,
                    options);

           /* 点击放大 imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    initImageView();
                }
            });*/

            imageViewList.add(imageView);//为数据源添加一项数据
            viewPageAdapter.notifyDataSetChanged();//通知UI更新*/
            // 加小白点, 指示器
            pointView = new View(context);
            pointView.setBackgroundResource(R.drawable.selector_bg_point);
            layoutParams = new LinearLayout.LayoutParams(10, 10);
            layoutParams.leftMargin = 10;
            // 设置默认所有都不可用
            pointView.setEnabled(false);
            ll_point_container.addView(pointView, layoutParams);
        }
        catch (Exception e)
        {
            MyToast.showToast(context,"加载图片错误");
        }
    }
    /**
     * 删除当前页面
     */
    public void delPage(int position)
    {
        position = position%imageViewList.size();
        imageViewList.remove(position);//删除一项数据源中的数据
        viewPageAdapter.notifyDataSetChanged();//通知UI更新
        ll_point_container.removeViewAt(position);
        viewPageAdapter.notifyDataSetChanged();//通知UI更新
    }

    private void initAdapter()
    {
        ll_point_container.getChildAt(0).setEnabled(true);
        previousSelectedPosition = 0;
        viewPageAdapter = new ViewPageAdapter(imageViewList);
        // 设置适配器
        viewPager.setAdapter(viewPageAdapter);
        // 默认设置到中间的某个位置
        int pos = Integer.MAX_VALUE / 2 - (Integer.MAX_VALUE / 2 % imageViewList.size());
        //2147483647 / 2 = 1073741823 - (1073741823 % 5)
        // 刚开始的时候 把当前页面是先到最大值的一半 为了循环滑动
        int currentItem = 0;
        // 让第一个当前页是 0
        //currentItem = currentItem - ((Integer.MAX_VALUE / 2) % 4);
        viewPager.setCurrentItem(currentItem);
    }

    public void init_workerinfo()
    {
        if(Config.rfidWorkerInfo.workernum.length()==0)
        {
            tv_log_statue.setText("未登录");
        }
        else
        {
            tv_log_statue.setText(Config.rfidWorkerInfo.workername);
        }
    }



    public void initElem() {


        timer.schedule(task,1000,1000);
        //Tv_style_size
        Tv_style_size.setHeight(Tv_style_size.getLineHeight() * 1);
        ivCall.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(iscalled==false)
                 popupWindow.showAtLocation(view,  Gravity.CENTER| Gravity.CENTER_HORIZONTAL, 0, 0);
                else
                    showAlertDialog("取消呼叫?",-1); ;
            }
        });


        ll_worker_more.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if(Config.rfidWorkerInfo.workernum.length()==0)
                {
                    MyToast.showToast(context,"  请先刷卡登录。。");
                    return;

                }


/*               if(isLogin==false)
               {
                   MyToast.showToast(context,"  请先刷卡登录。。");
                   return;
               }*/
               if(workerinfoDialog==null)
               {
                    workerinfoDialog = new WorkerinfoDialog(context,handler);
                    workerinfoDialog.show();
               }
                else
                    workerinfoDialog.show();
            }
        });

        ivstyle_more.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               // Log.i(TAG,"====StyleNumSizeInfoDialog ======");

                if(styleNumSizeInfoDialog==null)
                {
                    styleNumSizeInfoDialog = new StyleNumSizeInfoDialog(context, handler);
                    //styleNumSizeInfoDialog.show();
                }
                /*else
                    styleNumSizeInfoDialog.show();*/

                if(realData.order_id.length()==0)
                {
                    MyToast.showToast(context,"当前终端上的订单号为空");
                    return;
                }
                String url = DpsInterface.getStyleNumInfo(realData.order_id);
                httpsyncStyleNumInfo thread = new httpsyncStyleNumInfo(handler,context,url);
                thread.start();
            }
        });

    }



    LinearLayout ll_zuzhang;
    LinearLayout ll_jixiu;
    LinearLayout ll_wuliao;



    private void initContentview(View contentview) {
        ll_zuzhang = (LinearLayout) contentview.findViewById(R.id.ll_zuzhang);
        ll_jixiu = (LinearLayout) contentview.findViewById(R.id.ll_jixiu);
        ll_wuliao = (LinearLayout) contentview.findViewById(R.id.ll_wuliao);

        //
        ll_zuzhang.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                changeItemBackground(0);
             //if(coon==true)
                {
                    showAlertDialog("确定呼叫组长!",1);
                }
              //else showAlertDialog("服务端断开！",0);

            }
        });
        ll_jixiu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                changeItemBackground(1);
              //  if(coon==true)
                {
                    showAlertDialog("确定呼叫机修！",2);
                }
              //  else showAlertDialog("服务端断开！",0);
            }
        });
        ll_wuliao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                changeItemBackground(2);
              //  if(coon ==true)
                {
                    showAlertDialog("确定呼叫物料！",3);

                }//else showAlertDialog("服务端断开！",0);
            }
        });

    }

    private void showAlertDialog(String msg, final int type) {
       AlertDialog.Builder builder= new AlertDialog.Builder(context);
       builder.setTitle("注意").setMessage(msg);
       builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                //ok
                String name = null;
                String info = null;
                if(type==1)
                   // calltype = 1;
                    name = "leader";
                if(type==2)
                    //calltype = 2;
                    name = "repairer";
                if(type==3)
                   // calltype = 3;
                    name = "bom";

                    popupWindow.dismiss(); //隐藏
                    // 创建消息
                   // Bundle bundle2 = new Bundle();
                   // Message msg1;
                   // msg1 = calThread.mHandler.obtainMessage();//每发送一次都要重新获取
                   // msg1.setData(bundle2);
                    if(type==1||type==2||type==3)
                    {
                        try
                        {
                            JSONObject data = new JSONObject();
                            data.put("terminal_code",Config.qrCodeInfo.location);
                            if(Config.rfidWorkerInfo.workernum.length()==0) {
                                data.put("emp_code", realData.worker_id);
                                data.put("emp_name", realData.worker_name);
                            }
                            else
                            {
                                data.put("emp_name",Config.rfidWorkerInfo.workername);
                                data.put("emp_code", Config.rfidWorkerInfo.workernum);
                            }
                            data.put("call_type",name);
                            info = data.toString();
                        }
                        catch (JSONException e)
                        {
                            Log.i(TAG,e.toString());
                        }

                        String result ="";
                        try
                        {
                            result = URLEncoder.encode(info,"utf-8");
                        } catch (UnsupportedEncodingException e)
                        {
                            e.printStackTrace();
                            return;
                        }

/*                        String path ="http://" + Config.devConfig.web_addr+"/js/a/its/terminal/uploadCalling?info=";
                        String url=path+result;
                        Log.i(TAG,url);
                       // sendRequestCallIts(url);*/

                        String path ="http://" + Config.devConfig.web_addr+"/basic/equipmentCall/uploadCalling?info=";
                        String url=path+result+"&qrCode="+Config.qrcode;
                        Log.i(TAG,url);
                        sendRequestCallDps(url);

/*                      ivCall.setImageResource(R.drawable.animation1);
                        animationDrawable=(AnimationDrawable)ivCall.getDrawable();
                        animationDrawable.start();*/
                    }
                    if(type==-1)
                    {
                        iscalled = false;
                        animationDrawable.stop();
                        ivCall.setImageResource(R.mipmap.ic_hujiao);
                        try
                        {
                            JSONObject data1 = new JSONObject();
                            data1.put("terminal_code",Config.qrCodeInfo.location);
                            info = data1.toString();
                        }
                        catch (JSONException e)
                        {
                            Log.i(TAG,e.toString());
                        }

                        String result ="";
                        try
                        {
                            result = URLEncoder.encode(info,"utf-8");
                        } catch (UnsupportedEncodingException e)
                        {
                            e.printStackTrace();
                            return;
                        }

/*                        String path ="http://" + Config.devConfig.web_addr+"/js/a/its/terminal/cancelCalling?info=";
                        String url=path+result;
                        Log.i(TAG,url);
                        sendRequestCancleCallIts(url);*/


                        if(Config.rfidWorkerInfo.workernum.length()==0)
                        {
                            MyToast.showToast(context,"请先刷卡登录?");
                            return;
                        }

                        String path ="http://" + Config.devConfig.web_addr+"/basic/equipmentCall/cancelCalling?";
                        String tem = String.format("terminal_code=%s",Config.qrCodeInfo.location);
                        String url=path+tem+"&qrCode="+Config.qrcode;
                        Log.i(TAG,url);
                        sendRequestCancleCallIts(url);

                    }
                 //   calThread.mHandler.sendMessage(msg1);//用handler向主线程发送信息
            }
       });
       builder.setNegativeButton("取消", new DialogInterface.OnClickListener(){
           @Override
           public void onClick(DialogInterface dialog, int which) {
               //cancle
               popupWindow.dismiss(); //隐藏
              // calltype = 0;
           }

       });
       builder.show();
    }

    private void changeItemBackground(int itemIndex) {
        switch (itemIndex){
            case 0:
                ll_zuzhang.setBackgroundResource(R.drawable.bg_hulan_corner);
                ll_jixiu.setBackgroundResource(0);
                ll_wuliao.setBackgroundResource(0);
                break;
            case 1:
                ll_jixiu.setBackgroundResource(R.drawable.bg_hulan_corner);
                ll_zuzhang.setBackgroundResource(0);
                ll_wuliao.setBackgroundResource(0);
                break;
            case 2:
                ll_wuliao.setBackgroundResource(R.drawable.bg_hulan_corner);
                ll_zuzhang.setBackgroundResource(0);
                ll_jixiu.setBackgroundResource(0);
                break;
            default:
                break;
        }
    }
    /**
     * 需要界面重新展示时调用这个方法
     */
    @Override
    public void onHiddenChanged(boolean hidden) {
        // TODO Auto-generated method stub
        super.onHiddenChanged(hidden);
        if (!hidden) {
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        onDetach  =true;
        unbinder.unbind();
    }

    @Override
    public void onStart()
    {
        super.onStart();
        Log.i("TEST","frament2");
    }
    @Override
    public void onResume()
    {
        super.onResume();
        resume = 1;

    }

    @Override
    public void onStop()
    {
        super.onStop();
        resume = 0;
    }

    public void onDetach()
    {

      super.onDetach();
      try
        {
            onDetach  =true;
            Field childFragmentManager = Fragment.class.getDeclaredField("mChildFragmentManager");
            childFragmentManager.setAccessible(true);
            childFragmentManager.set(this, null);
            Log.i(TAG,"onDetach..........");


        } catch (NoSuchFieldException e)
        {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e)
        {
            throw new RuntimeException(e);
        }

    }


    /**
     * 播放系统默认提示音
     *
     * @return MediaPlayer对象
     *
     * @throws Exception
     */
    public void defaultMediaPlayer() throws Exception
    {
        Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        Ringtone r = RingtoneManager.getRingtone(context, notification);
        r.play();
    }

    private Boolean boundFlag = false;

    private Boolean hangFlag = false;
    //自定义handler类
    class ShiShiSuJuHandler extends Handler {
        @Override
        //接收别的线程的信息并处理
        public void handleMessage(Message msg) {
            int duration = 0;
            CharSequence text;
            Toast toast;
            Bundle bundle;
            duration = Toast.LENGTH_SHORT;
            Log.i(TAG, Integer.toString(msg.arg1));

            if (onDetach != false)
                return;

            try {
                switch (msg.arg1)
                {
                    case 1:
                        Bundle bundle0 = msg.getData();
                        gy_image_name = bundle0.get("image.info").toString();
                        if (!onDetach) {
                            image_gy.touchImg = BitmapFactory.decodeFile(gy_image_name);
                            if (image_gy.touchImg != null)
                            {
                                Log.i(TAG, gy_image_name);
                                image_gy.setImageBitmap(image_gy.touchImg);
                            }
                        }
                        break;
                    case 2:

                        Bundle bundle1 = msg.getData();
                        realData = bundle1.getParcelable("real.info");
                        if (!onDetach)
                        {
                            FlushRealData(realData.order_id,realData.hangerid,0,realData.lineproject);
                        }
                        break;

                    case 3:
                    {
                        Bundle bundle2 = msg.getData();
                        String state = bundle2.getString("websocket");
                        if (state.compareTo("net_disconnect") == 0) {
                            coon = false;
                            if (call_flag == true) {
                                animationDrawable.stop();
                                ivCall.setImageResource(R.mipmap.ic_hujiao);
                                calltype = -1;
                                deal_result = "";
                                iscalled = false;
                            }
                        }
                        if (state.compareTo("net_connect") == 0)
                            coon = true;
                        break;
                    }
                    case 20:
                    {

                        Bundle bundle20 = msg.getData();
                        WorkerInfo tmp = bundle20.getParcelable("workerinfo");

                        if(MyMqttClient.myClientConn==true)
                        //mqtt服务未连接的时候，不进行同步
                        {
                            MyMqttClient.workerSyncToDg(1,tmp.id);
                        }
                        else
                        {
                            MyToast.showToast(context,"mqtt服务未连接,无法在终端上进行用户登录，请尝试在吊挂软件上进行登录");
                            return;
                        }

                        MyToast.showToast(context,"登录成功");
                        tv_log_statue.setText(tmp.name);
                        isLogin = true;
                        if(workerinfoDialog==null)
                        {
                            workerinfoDialog = new WorkerinfoDialog(context,handler);
                        }
                        workerinfoDialog.iniData(tmp);
                        workerinfoDialog.show();
                        Config.Workerinfosyncflag = 1;
                        break;
                    }
                    case 21:
                    {
                        Bundle bundle21 = msg.getData();
                        String info = bundle21.getString("call");
                        MyToast.showToast(context, info);
                        break;
                    }
                    case 22:
                    {
                        Bundle bundle22 = msg.getData();
                        String info = bundle22.getString("callcancle");
                        MyToast.showToast(context, info);
                        break;
                    }
                    case 23:
                    {
                        Bundle bundle23 = msg.getData();
                        String info = bundle23.getString("exception");
                        Log.i(TAG,info);
                        MyToast.showToast(context, info);
                        break;

                    }
                    case 24:
                    {
                        Bundle bundle2 = msg.getData();
                        String info = bundle2.getString("sync");
                        MyToast.showToast(context, info);
                    }
                    break;

                    case 99:
                    {
                        if(Config.fragShenglineqc2!=null)
                        {
                            Config.fragShenglineqc2.flushproducessinfo(Config.globalrealorderid);
                        }

/*                      Tv_order_id.setText(DpsOrderInfo.orderid);
                        Tv_order_id.setInAnimation(InAnimationSet);
                        Tv_order_id.setOutAnimation(OutAnimationSet);*/


                        Tv_style_id.setText(DpsOrderInfo.styNum);
                        Tv_style_id.setInAnimation(InAnimationSet1);
                        Tv_style_id.setOutAnimation(OutAnimationSet1);

                        Tv_style_name.setText(DpsOrderInfo.styName);
                        Tv_style_name.setInAnimation(InAnimationSet2);
                        Tv_style_name.setOutAnimation(OutAnimationSet2);


                        Tv_order_num.setText(Integer.toString(DpsOrderInfo.orderNum));
                        Tv_order_num.setInAnimation(InAnimationSet3);
                        Tv_order_num.setOutAnimation(OutAnimationSet3);



                        Tv_custom_name.setText(DpsOrderInfo.csName);
                        Tv_custom_name.setInAnimation(InAnimationSet4);
                        Tv_custom_name.setOutAnimation(OutAnimationSet4);


                        Tv_hg_finish_num.setText(Integer.toString(DpsOrderInfo.finishQty));
                        Tv_hg_finish_num.setInAnimation(InAnimationSet4);
                        Tv_hg_finish_num.setOutAnimation(OutAnimationSet4);

                        Date date = new Date(DpsOrderInfo.agreeData);
                        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
                        String sd = sdf.format(date);
                        Tv_order_agree_date.setText(sd);
                        Tv_order_agree_date.setInAnimation(InAnimationSet5);
                        Tv_order_agree_date.setOutAnimation(OutAnimationSet5);

                        //==============
                        Tv_main_material.setText(DpsOrderInfo.mainMaterial);
                        Tv_style_colour.setText(DpsOrderInfo.color);
                        //暂且屏蔽掉
                        if(DpsOrderInfo.typeSizeNameInfo.size()>10000000)
                        {
                            Tv_style_size.setHeight(Tv_style_size.getLineHeight() * 1);
                            Tv_style_size.setText(DpsOrderInfo.typeSizeNameInfo.get(0).name + "#" + DpsOrderInfo.typeSizeNameInfo.get(0).qty);
                            Img_down_up.setImageResource(R.mipmap.ic_down);
                            Img_down_up.setVisibility(DpsOrderInfo.typeSizeNameInfo.size()> 1 ? View.VISIBLE : View.GONE);
                            ic_down_up_flag = 0;
                            //根据高度来判断是否需要再点击展开
/*                            Tv_style_size.post(new Runnable() {
                                @Override
                                public void run() {
                                    Img_down_up.setImageResource(R.mipmap.ic_down);
                                    Img_down_up.setVisibility(DpsOrderInfo.typeSizeNameInfo.size()> 1 ? View.VISIBLE : View.GONE);
                                }
                            });*/
                        }
                    }
                    break;
                    case 100:
                    {
                        String des="";
                        /*for (int i=0;i<DpsOrderInfo.nameList.size();i++)
                        {
                            des =des+1+ i+"."+DpsOrderInfo.nameList.get(i).toString()+"\n";
                        }*/
                        String name="";
                        String note="";
                        DpsOrderInfo.standardLabourTime = 0;
                        boundFlag = false;
                        hangFlag = false;

                        int producessSize = DpsOrderInfo.nameTypeArrayList.size();
                        for (int i=0;i<producessSize;i++)
                        {
                            int k = 1+i;
                            des = des+k+"."+DpsOrderInfo.nameTypeArrayList.get(i).name+" #"+
                                    DpsOrderInfo.nameTypeArrayList.get(i).time+"s"+"\n";
                            if(DpsOrderInfo.nameTypeArrayList.get(i).name.indexOf("绑定工序")>=0||
                                    DpsOrderInfo.nameTypeArrayList.get(i).name.compareTo("产品ID码2次绑定工序")==0)
                            {
                                boundFlag = true;
                            }
                            else if(DpsOrderInfo.nameTypeArrayList.get(i).name.indexOf("挂片")>=0)
                            {
                                hangFlag = true;
                            }
                            else
                            {

                            }
                            DpsOrderInfo.standardLabourTime = DpsOrderInfo.standardLabourTime+
                                    Integer.parseInt(DpsOrderInfo.nameTypeArrayList.get(i).time);
                        }

                        //同个衣架刷新的时候不进行重新计时
                        if(refreshAgainFlag == false)
                        {
                            Tv_standard_time.setText(Integer.toString(DpsOrderInfo.standardLabourTime) + "s");
                            index = 0;
                            progress_bar_start = 1;
                        }

                        //有效的标准工时
                 /*       if(DpsOrderInfo.standardLabourTime!=0)
                        {
                            progress_bar_start = 1; //有效的标准工时
                        }
                        else
                        {
                            progress_bar_start = 0;
                        }*/
                        progress_bar.setMax(DpsOrderInfo.standardLabourTime);
                        progress_bar.setProgress(index);
                        Tv_worke_time.setText(Integer.toString(index)+"s");

                        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        String t=format.format(new Date());
                        if(producessSize == 0)
                            des = "该站位路线图里没有安排工序....";
                        des = des+t;
                        Tv_opera_desc.setText(des);
                        if(boundFlag==true)
                        {
                            Tv_opera_desc.setBackgroundColor(0xFF5ED5D1);
                        }
                        else if(hangFlag==true)
                        {
                            Tv_opera_desc.setBackgroundColor(0xFFF6D6FF);
                        }
                        else
                        {
                            Tv_opera_desc.setBackgroundColor(0xFFFFFF);
                        }

                        if(producessSize == 0)
                        {
                            Tv_opera_desc.setTextColor(0xFF1EB4A8);
                        }
                        else
                        {
                            Tv_opera_desc.setTextColor(0xff000000);
                        }

                        Log.i(TAG, "name list size: " + Integer.toString(DpsOrderInfo.nameList.size()));
       /*               String style_size="";
                        int k= 0;
                        for(k =0;k<DpsOrderInfo.typeSizeNameInfo.size();k++)
                        {
                            style_size = style_size+DpsOrderInfo.typeSizeNameInfo.get(k).name+
                                    DpsOrderInfo.typeSizeNameInfo.get(k).qty+"\n";
                        }*/
                        /*Tv_style_size.setHeight(Tv_style_size.getLineHeight() * k);*/

                        int count = viewPageAdapter.getCount();
                        Log.i(TAG, "viewPageAdapter size: " + Integer.toString(count));
                        Log.i(TAG, "urlpic list size: " + Integer.toString(DpsOrderInfo.urlList.size()));

                        if(lastProcessPicUrlCacheTmp.compareTo(lastProcessPicUrlCache)==0)
                        {
                           //return;
                        }
                        else
                        {
                           //lastProcessPicUrlCacheTmp = lastProcessPicUrlCache;
                        }
                        if (count > 0)
                        {
                            for (int i = 0; i < count; i++)
                            {
                                delPage(0);
                            }
                        }
                        for (int i = 0; i < DpsOrderInfo.urlList.size(); i++)
                        {
                            addUrlIamgePage(DpsOrderInfo.urlList.get(i));
                        }
                    }
                    break;
                    case 199:
                        {
                        int len = Config.styeNumInfo.sizeList.size();
                        if (len>0)
                        {
                            List<String> tmp = new ArrayList<>();
                            int colum = Config.styeNumInfo.sizeList.get(0).s.size();
                            for (int i=0;i<len;i++)
                            {
                                int size0 = Config.styeNumInfo.sizeList.get(i).s.size();
                                for (int k = 0;k<colum;k++)
                                {
                                    //默认以第一列表的数据为最大列个数默认表头
                                    if(k<size0)
                                        tmp.add(Config.styeNumInfo.sizeList.get(i).s.get(k)) ;
                                    else
                                        tmp.add("#") ;
                                }
                            }
                            styleNumSizeInfoDialog.update(tmp,colum);
                            styleNumSizeInfoDialog.show();
                        }
                        else
                        {
                            MyToast.showToast(context,"改款的尺寸详情系统里为空");
                        }
                    }
                        break;

                    case 33:
                    {
                        animationDrawable = (AnimationDrawable) ivCall.getDrawable();
                        animationDrawable.stop();
                        ivCall.setImageResource(R.mipmap.ic_hujiao);
                        Bundle bundle2 = msg.getData();
                        String info = bundle2.getString("exception");
                        MyToast.showToast(context, info);
                    }
                    break;

                    case 120:
                    {
                        tv_log_statue.setText("未登录");
                        new MessageToUi().send(120,"info","workerinfoupdate",Activityhandler);
                    }
                    break;
                    case 801:
                    {
                        tv_log_statue.setText(Config.rfidWorkerInfo.workername);
                        if(workerinfoDialog==null)
                        {
                            workerinfoDialog = new WorkerinfoDialog(context,handler);
                        }
                        Bundle bundle801 = msg.getData();
                        WorkerInfo tmp = bundle801.getParcelable("dg.worker.info.update");
                        workerinfoDialog.iniData(tmp);
                    }
                    break;

                    case 254: {
                        text = "请求工艺信息，返回值：" + msg.obj;
                        toast = Toast.makeText(context, text, duration);
                        toast.show();
                        break;
                    }
                    case 255:
                    case 256: {

                        break;
                    }
                    case 257: {
                        break;
                    }
                    case 258: {
                        File tmp = (File) msg.obj;
                        Bitmap bm = BitmapFactory.decodeFile(tmp.toString());

                        image_gy.touchImg = bm;
                        image_gy.setImageBitmap(image_gy.touchImg);
                        break;
                    }

                    case 300:
                        {
                        text = "呼叫错误，返回值:" + msg.obj;
                        toast = Toast.makeText(context, text, duration);
                        toast.show();

                    }
                    break;
                    case 301:
                        {
                        text = "呼叫成功！";
                        toast = Toast.makeText(context, text, duration);
                        toast.show();

                        ivCall.setImageResource(R.drawable.animation1);
                        animationDrawable = (AnimationDrawable) ivCall.getDrawable();
                        animationDrawable.start();
                        iscalled = true;


                    }
                    break;

                    case 302: {
                        text = "呼叫失败！";
                        toast = Toast.makeText(context, text, duration);
                        toast.show();


                    }
                    break;


                    case 400: {
                        text = "呼叫取消错误，返回值:" + msg.obj;
                        toast = Toast.makeText(context, text, duration);
                        toast.show();
                    }
                    break;
                    case 401: {
                        text = "呼叫取消成功！";
                        toast = Toast.makeText(context, text, duration);
                        toast.show();
                        iscalled = false;
                    }
                    break;

                    case 402:
                        {
                        text = "呼叫取消失败！";
                        toast = Toast.makeText(context, text, duration);
                        toast.show();
                    }
                    break;
                    case 800:
                    {
                        Bundle bundle800 = msg.getData();
                        String info = bundle800.getString("order.return");
                        Log.i(TAG,info);
                        if(info.compareTo("success")==0)
                            MyToast.showLongToast(context, "工序返修成功！");
                        else
                            MyToast.showLongToast(context, "改道工序返修失败！");
                    }
                    break;
                    case 802:
                    {
                        Bundle bundle800 = msg.getData();
                        String info = bundle800.getString("order.return");
                        Log.i(TAG,info);
                        MyToast.showLongToast(context, "返修失败："+info);
                    }
                    break;
                    case 900:
                    {

                        if(boundFlag==false&&hangFlag==false)
                        {
                            MyToast.showToast(context,"改站位不是绑定工序、挂片站位");
                            return;
                        }

                        bundle = msg.getData();
                        String barcode = bundle.getString("qrcode");

                        if(boundFlag) //
                        {
                            String orderId = realData.order_id;
                            String styleId = DpsOrderInfo.styNum;
                            String styleName = DpsOrderInfo.styName;
                            String colorId = realData.style_colour;
                            String sizeId = realData.style_size;
                            String lineNum = realData.lineproject;
                            String hanger = realData.hangerid;
                            String orderNum = Integer.toString(DpsOrderInfo.orderNum);
                            if (qrCodeBoundDialog == null) {
                                qrCodeBoundDialog = new QrCodeBoundDialog(context, handler);
                                qrCodeBoundDialog.refushData(barcode, orderId,
                                        styleId, styleName, colorId, sizeId, lineNum, hanger, orderNum);
                                qrCodeBoundDialog.show();
                            } else
                                {
                                qrCodeBoundDialog.refushData(barcode, orderId,
                                        styleId, styleName, colorId, sizeId, lineNum, hanger, orderNum);
                                qrCodeBoundDialog.dismiss();
                                qrCodeBoundDialog.show();
                            }
                        }
                        if(hangFlag)
                        {
                            String url = DpsInterface.getRelationInfo(barcode,Config.qrcode);
                            Log.i(TAG,url);
                            String arg[] = new String[10];
                            arg[0] = barcode;
                            HttpGetThread thread = new HttpGetThread(handler, context, url, 1, "getRelationInfo", arg);
                            thread.start();
                            if(qrCodeSwitchDialog!=null) //加载前 默认关掉前一次的对话框,请求成功后再次显示
                            {
                                qrCodeSwitchDialog.dismiss();
                            }

                        }
                    }
                        break;
                    case 901:
                    {

                        bundle = msg.getData();
                        String qrcode = bundle.getString("data");

                        //JSON 序列化数据，直接放全局，不再重新定义序列化数据格式
                        //MyToast.showToast(context,ss);

                        if(qrCodeSwitchDialog==null)
                        {
                            qrCodeSwitchDialog = new QrCodeSwitchDialog(context,handler);
                            qrCodeSwitchDialog.refushData(qrcode,DpsOrderInfo.switchData);
                            qrCodeSwitchDialog.show();
                        }
                        else
                        {
                            qrCodeSwitchDialog.refushData(qrcode,DpsOrderInfo.switchData);
                            qrCodeSwitchDialog.show();
                        }

                    }
                        break;


                    default:
                        break;
                }
            } catch (Exception e)
            {
               Log.e(TAG,e.toString()) ;
                MyToast.showToast(context,e.toString());
            }
        }
    }

    private int index=0;
    private int progress_bar_start = 0;
    class TimerHandler extends Handler
    {
        @Override
        //接收别的线程的信息并处理
        public void handleMessage(Message msg)
        {
            try
            {
                if (onDetach != false)
                    return;

                //Log.i(TAG, "TimeerHandler arg:" + Integer.toString(msg.arg1));
                switch (msg.arg1)
                {
                    case 1:
                    {
                        if(progress_bar_start==0)
                            return;

                        if(index>=1800)
                        {
                            Tv_worke_time.setText(Integer.toString(index)+"s"+"#已超时");
                            return;
                        }

                        index++;
                        if(index>=DpsOrderInfo.standardLabourTime)
                        {
                            Tv_worke_time.setText(Integer.toString(index)+"s"+"#已超时");
                            return;
                        }

                        progress_bar.setProgress(index);
                        Tv_worke_time.setText(Integer.toString(index)+"s");
                    }
                    break;
                    default:
                        break;
                }
            }
            catch (Exception e)
            {
                Log.e(TAG,e.toString());
                MyToast.showToast(context,"TimerHandler:"+e.toString());
            }
        }
    }

    private  int refreshAgainNo = 0;
    private  boolean refreshAgainFlag = false ;
    public void FlushRealData(String order_id,String hangerId,int type,String lineproject)
    {
       try
       {

           Tv_order_id.setText(order_id);
           Tv_order_id.setInAnimation(InAnimationSet);
           Tv_order_id.setOutAnimation(OutAnimationSet);
           Config.globalrealorderid = order_id;
           Tv_hangerid.setText("衣架:"+hangerId+"#"+lineproject);

           if(order_id.length()==0)
           {
               MyToast.showToast(context,"订单编号为空?");
               return;
           }
           if(Config.rfidWorkerInfo.workernum.length()==0)
           {
               MyToast.showToast(context,"请先登录?");
               return;
           }

           if(Config.qrCodeInfo.location.length()!=6)
           {
                MyToast.showToast(context,"设备二维码信息未绑定或绑定错误？");
                return;
           }

           if(Config.fragShenglineqc2!=null)
           {
                Config.fragShenglineqc2.flushproducessinfo(order_id);
           }


            /*DPS 获取订单信息接口*/
            String path ="http://" + Config.devConfig.web_addr+"/pis/orderPaSub/getStationInfoByPannel?";
            String line;
            String workerid;
            workerid =Config.rfidWorkerInfo.workernum;
            String url=path+"po="+order_id+"&station="+Config.qrCodeInfo.location
                    +"&workNum="+workerid+
                    "&qrCode="+Config.qrcode+
                    "&lineNum="+lineproject;


            if(type==1)//rfid signal
            {
                lastCache = "null";
                lastCacheNo = 0;

                lastProcessCache = "";
                lastProcessCacheNo = 0;

                lastProcessPicUrlCache="";
                lastProcessPicUrlCacheNo= 0;
                lastProcessPicUrlCacheTmp="";
            }




        if(lastHangerId.compareTo(hangerId)!=0)
        {
            Tv_standard_time.setText(Integer.toString(DpsOrderInfo.standardLabourTime)+"s");
            index= 0;
            progress_bar_start = 1;
            progress_bar.setMax(DpsOrderInfo.standardLabourTime);
            progress_bar.setProgress(index);
            Tv_worke_time.setText(Integer.toString(index)+"s");
            lastHangerId = hangerId;
            refreshAgainNo = 0;
            refreshAgainFlag = false;


            sendRequestWithHttpClient(url);
        }
        //如果的一直是同一个衣架的话,每60s后请求一次，its推送5s周期
        if(lastHangerId.compareTo(hangerId)==0)
        {
            refreshAgainNo++;
        }

        int num = 12;
            //该处理方式是为了尽快刷新数据 60s
        if(refreshAgainNo >num)
        {
            refreshAgainFlag = true;
            sendRequestWithHttpClient(url);
            refreshAgainNo = 0;
        }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }

    }
    private void sendRequestWithHttpClient(final String url)
    {
        if(Config.qrCodeInfo.location.length()!=6)
        {
            MyToast.showToast(context,"设备二维码信息未绑定或绑定错误？");
            return;
        }
        if(Config.rfidWorkerInfo.workernum.length()==0)
        {
            MyToast.showToast(context,"请先刷卡登录?");
            return;
        }
        //MyToast.showToast(context,"订单号获取成功！");
        httpsync thread = new httpsync(handler,context,url);
        thread.start();
    }

    private void sendRequestCallIts(final String url)
    {
        httpcall thread = new httpcall(handler,context,url);
        thread.start();
    }

    private void sendRequestCallDps(final String url)
    {

        if(Config.qrCodeInfo.location.length()!=6)
        {
            MyToast.showToast(context,"设备二维码信息未绑定或绑定错误？");
            return;
        }
        if(Config.rfidWorkerInfo.workernum.length()==0)
        {
            MyToast.showToast(context,"请先刷卡登录?");
            return;
        }

        httpcall thread = new httpcall(handler,context,url);
        thread.start();
    }
    private void sendRequestCancleCallIts(final String url)
    {
        if(Config.qrCodeInfo.location.length()!=6)
        {
            MyToast.showToast(context,"设备二维码信息未绑定或绑定错误？");
            return;
        }
        if(Config.rfidWorkerInfo.workernum.length()==0)
        {
            MyToast.showToast(context,"请先刷卡登录?");
            return;
        }

        httpcanclecall thread = new httpcanclecall(handler,context,url);
        thread.start();
    }

    public void sendRequestLogon(final String worknum)
    {
        Config A = new Config(context);
        Config.DpsInterface dpsInterface = A.new DpsInterface(Config.devConfig.web_addr);
        String arg = "workNum="+worknum;
        String url = dpsInterface.logon+arg;
        workerlogon thread = new workerlogon(handler,context,url);
        thread.start();
    }
    public class workerlogon extends Thread {
        public Context context0 = null;
        public Handler handler0 = null;
        public String Url = null;
        //http://192.168.100.212:8046/basic/worker/findByWorNum?workNum=00210
        public workerlogon(Handler handlerin, Context contextin, String url) {
            handler0 = handlerin;
            context0 = contextin;
            Url = url;
        }
        public void run() {
            Message msg1;
            String result = "";
            HttpClient httpCient = new DefaultHttpClient();
            try
            {
                HttpGet httpGet = new HttpGet(Url);

                httpCient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,3000);//连接时间
                httpCient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,2000);//数据传输时间
                int code = -1;

                Log.i(TAG, Url);
                HttpResponse response = httpCient.execute(httpGet);
                code = response.getStatusLine().getStatusCode();
                Log.i(TAG, "get call reponse code: " + Integer.toString(code));
                if (response.getStatusLine().getStatusCode() == 200) {
                    HttpEntity entity = response.getEntity();
                    result = EntityUtils.toString(entity, HTTP.UTF_8);
                    Log.i(TAG, result);
                    JSONObject jsonObj = new JSONObject(result);
                    if (jsonObj == null)
                        return;
                    if (jsonObj.has("data") == true) {
                        Log.i(TAG, "获取员工信息成功！");
                        isLogin = true;
                        JSONObject data = jsonObj.optJSONObject("data");
                        String name = data.optString("name");
                        String workNum = data.optString("workNum");
                        String line = data.optString("lineNum");
                        WorkerInfo tmp = new WorkerInfo();
                        tmp.name = name;
                        tmp.id = workNum;
                        tmp.line = line;

                        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// HH:mm:ss
                        Date date = new Date(System.currentTimeMillis());
                        String time = simpleDateFormat.format(date);
                        tmp.logontime = time;


                        new MessageToUi().sendParcelable(20,"workerinfo",tmp,handler0);
                        new MessageToUi().sendParcelable(20,"workerinfo",tmp,Activityhandler);

                    }
                    if (jsonObj.has("error") == true)
                    {
                        JSONObject error = jsonObj.optJSONObject("error");
                        String message = error.optString("message");
                        Log.i(TAG, "获取员工信息失败！");
                        new MessageToUi().send(23,"exception",message,handler0);
                    }

                }
                else
                {
                    String s = "登录时，服务端返回："+code;
                    new MessageToUi().send(23,"exception",s,handler0);
                }
            }
            catch (JSONException e)
            {
                e.printStackTrace();
                new MessageToUi().send(23,"exception",e.toString(),handler0);


            }
            catch (Exception e)
            {
                Log.e(TAG, "HTTP request err......");
                e.printStackTrace();
                new MessageToUi().send(23,"exception",e.toString(),handler0);
            }


        }

    }

    public class httpcanclecall extends Thread {
        public Context context0 = null;
        public Handler handler0 = null;
        public String Url = null;

        public httpcanclecall(Handler handlerin, Context contextin, String url) {
            handler0 = handlerin;
            context0 = contextin;
            Url = url;
        }

        public void run()
        {
            Message msg1;
            String result = "";
            String imageUrl = "";
            HttpClient httpCient = new DefaultHttpClient();
            int code = -1;
            try
            {
                HttpGet httpGet = new HttpGet(Url);
                httpCient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,3000);//连接时间
                httpCient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,2000);//数据传输时间

                Log.i(TAG, Url);
                HttpResponse response = httpCient.execute(httpGet);
                code = response.getStatusLine().getStatusCode();
                Log.i(TAG, "get call reponse code: "+Integer.toString(code));
                if (response.getStatusLine().getStatusCode() == 200)
                {
                    HttpEntity entity = response.getEntity();
                    result = EntityUtils.toString(entity, HTTP.UTF_8);
                    Log.i(TAG, result);
                    try {
                        JSONObject jsonObj = new JSONObject(result);
                        if (jsonObj == null)
                            return;
                        //ITS
                        if(jsonObj.has("result")==true)
                        {

                            if (jsonObj.has("result") ==true)
                            {
                                Log.i(TAG, "its 呼叫取消成功！");
                                String s = "呼叫取消成功";
                                new MessageToUi().send(22,"callcancle",s,handler0);
                            }
                            else
                            {
                                Log.i(TAG, "its呼叫取消失败！");
                                String s = "呼叫取消失败";
                                new MessageToUi().send(22,"callcancle",s,handler0);
                            }
                        }

                        if(jsonObj.has("data")==true)
                        {
                            Log.i(TAG, "dps呼叫取消成功！");
                            String s = "呼叫取消成功";
                            new MessageToUi().send(22,"callcancle",s,handler0);
                        }

                        if(jsonObj.has("error")==true)
                        {
                            JSONObject error = jsonObj.optJSONObject("error");
                            String message = error.optString("message");
                            Log.i(TAG, "dps 呼叫取消失败！");
                            String s = "呼叫取消失败: "+message;
                            new MessageToUi().send(22,"callcancle",s,handler0);
                        }
                    }
                    catch (JSONException e)
                    {
                        e.printStackTrace();
                        new MessageToUi().send(23,"exception",e.toString(),handler0);
                    }
                }
                else
                {
                    String err  ="服务端返回： "+code;
                    new MessageToUi().send(22,"http",err,handler0);
                    return;
                }
            }catch (Exception e)
            {
                new MessageToUi().send(23,"exception",e.toString(),handler0);
                Log.e(TAG, "HTTP request err......");
                e.printStackTrace();
                return;
            }


        }
    }

    public class httpcall extends Thread {
        public Context context0 = null;
        public Handler handler0 = null;
        public String Url = null;

        public httpcall(Handler handlerin, Context contextin, String url) {
            handler0 = handlerin;
            context0 = contextin;
            Url = url;
        }
        public void run()
        {
            Message msg1;
            String result = "";
            HttpClient httpCient = new DefaultHttpClient();
            try
            {
                HttpGet httpGet = new HttpGet(Url);
                httpCient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,3000);//连接时间
                httpCient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,2000);//数据传输时间
                int code = -1;

                Log.i(TAG, Url);
                HttpResponse response = httpCient.execute(httpGet);
                code = response.getStatusLine().getStatusCode();
                Log.i(TAG, "get call reponse code: "+Integer.toString(code));
                if (response.getStatusLine().getStatusCode() == 200)
                {
                    HttpEntity entity = response.getEntity();
                    result = EntityUtils.toString(entity, HTTP.UTF_8);
                    Log.i(TAG, result);
                    try {
                        JSONObject jsonObj = new JSONObject(result);
                        if (jsonObj == null)
                            return;

                        //ITS
                        if(jsonObj.has("result")==true)
                        {

                            if (jsonObj.has("result") == true)
                            {
                                Log.i(TAG, "its 呼叫成功！");
                                String s = "呼叫成功";
                                new MessageToUi().send(301,"call",s,handler0);
                            }
                            else
                            {
                                Log.i(TAG, "its呼叫失败！");
                                String s = "呼叫失败";

                                new MessageToUi().send(21,"call",s,handler0);

                            }
                        }

                        if(jsonObj.has("data")==true)
                        {
                            Log.i(TAG, "dps呼叫成功！");
                            String s = "呼叫成功";
                            new MessageToUi().send(301,"call",s,handler0);


                        }

                        if(jsonObj.has("error")==true)
                        {
                            JSONObject error = jsonObj.optJSONObject("error");
                            String message = error.optString("message");
                            Log.i(TAG, "dps 呼叫失败！");
                            String s = "呼叫失败: "+message;
                            new MessageToUi().send(21,"call",s,handler0);
                        }

                    }
                    catch (JSONException e)
                    {
                        e.printStackTrace();
                        new MessageToUi().send(23,"exception",e.toString(),handler0);
                }
                }
                else
                {
                    String s = "服务端返回："+code;
                    new MessageToUi().send(23,"exception",s,handler0);
                }
            }catch (Exception e)
            {

                new MessageToUi().send(23,"exception",e.toString(),handler0);
                Log.e(TAG, "HTTP request err......");
                e.printStackTrace();

            }
        }
    }


    public class httpsync extends Thread {
        public Context context0 = null;
        public Handler handler0 = null;
        public String Url = null;


        public httpsync(Handler handlerin, Context contextin, String url)
        {
            handler0 = handlerin;
            context0 = contextin;
            Url = url;

        }

        public void run() {

            Message msg1;
            String result = "";
            String imageUrl = "";
            HttpClient httpCient = new DefaultHttpClient();
            int code = -1;
            try
            {
                HttpGet httpGet = new HttpGet(Url);
                httpCient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,3000);//连接时间
                httpCient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,2000);//数据传输时间

                Log.i(TAG, Url);
                HttpResponse response = httpCient.execute(httpGet);
                code = response.getStatusLine().getStatusCode();
                Log.i(TAG, "get orderinfo reponse code: "+Integer.toString(code));
                if (response.getStatusLine().getStatusCode() == 200)
                {
                    HttpEntity entity = response.getEntity();
                    result = EntityUtils.toString(entity, HTTP.UTF_8);
                    Log.i(TAG, result);
                }
                else
                {
                    String s = "服务端返回："+code;
                    new MessageToUi().send(24,"sync",s,handler0);
                    return;
                }
            }
            catch (Exception e)
            {
                lastCache = "null";//网络错误，需要重新刷新赋值缓存
                Log.e(TAG, "HTTP request err......");
                e.printStackTrace();
                new MessageToUi().send(23,"exception",e.toString(),handler0);
                return;
            }
            try
            {
                JSONObject jsonObj = new JSONObject(result);
                if (jsonObj == null)
                    return;
                else
                {
                    if(jsonObj.has("error")==true)
                    {
                       JSONObject error = jsonObj.optJSONObject("error");
                       if (error != null)
                       {
                           String message ="获取工艺信息错误：" +error.optString("message");
                           new MessageToUi().send(23,"exception",message,handler0);
                           return;
                       }
                    }
                    else
                    {
                        if(lastCacheNo>=0)//每60个周期清除一次缓存,0时不做缓存处理
                        {
                            lastCacheNo = 0;
                            lastCache="null";
                        }
                        if(lastCache.compareTo(result)==0)
                        {
                            Log.i(TAG,"返回数据与上次一样！");
                            lastCacheNo++;
                            return;
                        }
                        else
                        {
                            lastProcessCache = "";
                            lastProcessCacheNo = 0;
                            lastProcessPicUrlCache="";
                            lastProcessPicUrlCacheNo= 0;
                        }
                        lastCache=result; //避免重复刷新UI

                        if(jsonObj.has("data")==true)
                        {

                            JSONObject data = jsonObj.optJSONObject("data");
                            if(data.has("poInfoEv")==true)
                            {
                             //   {"meta":null,"data":{"nameNodeList":[{"name":"产品ID码2次绑定工序","time":135}],"nameList":["产品ID码2次绑定工序"],"poInfoEv":{"id":1338,"po":"D190625-0006","procInstId":"D190625-0006/6","qty":500,"agreedDate":1562601600000,"comfort":"合体","remark":"","creator":"yang","styNum":"LS0612","customerStyleNum":"0612","styName":"利世","isUrgent":0,"typeNameInfo":"[{\"qty\": \"0\", \"name\": \"84A\"}, {\"qty\": \"500\", \"name\": \"88A\"}, {\"qty\": \"0\", \"name\": \"92A\"}, {\"qty\": \"0\", \"name\": \"96B\"}, {\"qty\": \"0\", \"name\": \"100B\"}, {\"qty\": \"0\", \"name\": \"104B\"}]","typeNameList":[{"qty":500,"name":"88A"}],"csNum":"10000563","csName":"LilyGuan","csPhone":"14785698711","orderType":2,"lineNum":null,"isZoom":2,"mainMaterial":"面料","color":"紫色","gradeVersion":"ET","orderSn":null,"editor":null,"editTime":null,"version":"5.0.0","status":4},"urlList":[],"finishQty":0}}


                                JSONObject poInfoEv = data.optJSONObject("poInfoEv");
                                DpsOrderInfo.orderid = poInfoEv.optString("procInstId");
                                DpsOrderInfo.orderNum = poInfoEv.optInt("qty");
                                DpsOrderInfo.agreeData = poInfoEv.optLong("agreedDate");
                                DpsOrderInfo.comfort = poInfoEv.optString("comfort");
                                DpsOrderInfo.remark = poInfoEv.optString("remark");
                                DpsOrderInfo.creator = poInfoEv.optString("creator");
                                DpsOrderInfo.styNum = poInfoEv.optString("styNum");
                                DpsOrderInfo.styName = poInfoEv.optString("styName");
                                DpsOrderInfo.isUrgent = poInfoEv.optInt("isUrgent");
                                DpsOrderInfo.csNum = poInfoEv.optString("csNum");
                                DpsOrderInfo.csName = poInfoEv.optString("csName");
                                DpsOrderInfo.orderType = poInfoEv.optInt("orderType");
                                DpsOrderInfo.lineNum = poInfoEv.optString("lineNum");
                                DpsOrderInfo.isZoom = poInfoEv.optInt("isZoom");
                                DpsOrderInfo.mainMaterial = poInfoEv.optString("mainMaterial");
                                DpsOrderInfo.color = poInfoEv.optString("color");
                                DpsOrderInfo.orderSn = poInfoEv.optString("orderSn");
                                DpsOrderInfo.editor = poInfoEv.optString("editor");
                                DpsOrderInfo.editTime = poInfoEv.optString("editTime");
                                DpsOrderInfo.version = poInfoEv.optString("version");
                                DpsOrderInfo.status = poInfoEv.optInt("status");



                                //
                                JSONArray typesizeInfo = poInfoEv.optJSONArray("typeNameList");
                                if(typesizeInfo!=null)
                                {
                                    DpsOrderInfo.typeSizeNameInfo.clear();
                                    for (int k = 0; k < typesizeInfo.length(); k++)
                                    {
                                        DpsOrderInfo.typeNameInfo tmp = new DpsOrderInfo().new typeNameInfo();
                                        JSONObject obj = typesizeInfo.optJSONObject(k);
                                        tmp.name = obj.optString("name");
                                        tmp.qty = obj.optString("qty");
                                        DpsOrderInfo.typeSizeNameInfo.add(tmp);
                                      //Log.i(TAG,tmp.name+"   "+tmp.qty);
                                    }
                                }
                                else
                                {
                                    Log.i(TAG,"NULL");
                                    DpsOrderInfo.typeSizeNameInfo.clear();
                                }
                                //
                                new MessageToUi().send(99, "info", "updateUiOrderInfo", handler0);
                            }

                            int finishQty = data.optInt("finishQty");
                            DpsOrderInfo.finishQty = finishQty;


                            JSONArray array0 = data.optJSONArray("urlList");
                            if(array0!=null)
                            {
                                int size = array0.length();
                                imageUrl = array0.toString();
                                //if(imageUrl.compareTo(lastProcessPicUrlCache)!=0)
                                {
                                    lastProcessPicUrlCache = imageUrl;
                                }

                                if(size<0)
                                {
                                    String err  ="请至少上传一张工艺图片！";
                                    new MessageToUi().send(23,"exception",err,handler0);
                                }
                                else
                                {
                                    DpsOrderInfo.urlList.clear();
                                    for (int i = 0; i < size; i++)
                                    {
                                        String s = array0.optString(i);
                                        DpsOrderInfo.urlList.add(s);
                                        Log.i(TAG,s);
                                    }
                                }
                            }
                            else
                            {
                                DpsOrderInfo.urlList.clear();
                            }

                            //
                            JSONArray array1 = data.optJSONArray("nameNodeList");
                            if(array1!=null)
                            {
                                int size = array1.length();
                                if(size<0)
                                {
                                    String err  ="请至少提供一道工序名称！";
                                    new MessageToUi().send(23,"exception",err,handler0);
                                }
                                else
                                {
                                    /* 20190514 delte
                                    DpsOrderInfo.nameList.clear();
                                    for (int i = 0; i < size; i++)
                                    {
                                        String s = array1.optString(i);
                                        DpsOrderInfo.nameList.add(s);
                                    }*/

                                    DpsOrderInfo.nameTypeArrayList.clear();

                                    for (int i=0;i<size;i++)
                                    {
                                        DpsOrderInfo.NameType tmp = new DpsOrderInfo().new NameType();
                                        JSONObject obj = array1.optJSONObject(i);
                                        tmp.name = obj.optString("name");
                                        tmp.time = obj.optString("time");
                                        tmp.note = obj.optString("note");
                                        DpsOrderInfo.nameTypeArrayList.add(tmp);
                                    }

                                }
                            }
                            else
                            {
                                DpsOrderInfo.nameList.clear();
                                DpsOrderInfo.nameTypeArrayList.clear();
                            }
                            new MessageToUi().send(100,"info","updateUiOrderInfo",handler0);
                        }

                        DpsOrderInfo.orderInfoWrite(result);//save data
                    }

                }
            }
            catch (JSONException e)
            {
                e.printStackTrace();
                new MessageToUi().send(23,"exception",e.toString(),handler0);
            }
            /*try
            {
                if(imageUrl.length()==5550)
                {

                    URL url = new URL(imageUrl);
                   // InputStream inputStream=url.openStream();
     *//*               Bitmap bm=BitmapFactory.decodeStream(url.openStream());
                    msg1=handler0.obtainMessage();
                    msg1.arg1 = 258;
                    msg1.obj = bm;
                    handler0.sendMessage(msg1);
                    inputStream.close(); *//*

                    //获取连接对象，并没有建立连接
                    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                    //设置连接和读取超时
                    conn.setConnectTimeout(5000);
                    //conn.setReadTimeout(5000);
                    //设置请求方法，注意必须大写
                    conn.setRequestMethod("GET");
                    //建立连接，发送get请求
                    conn.connect();
                    //建立连接，然后获取响应吗，200说明请求成功
                    int repcode = conn.getResponseCode();
                    Log.i(TAG,"get pic reponde:"+Integer.toString(repcode));

                    if(repcode ==HttpURLConnection.HTTP_OK)
                    {

                        //拿到服务器返回的输入流
                        InputStream is = conn.getInputStream();

                        //1 把流里的数据读取出来，并构造成图片
                        //Bitmap bm = BitmapFactory.decodeStream(is);
                        //加入缓存
                        int index = imageUrl.lastIndexOf(".");
                        String name = Config.imagepath+"/image0."+imageUrl.substring(index + 1);
                        final File file = new File(name);
                        //2.把流里的数据读取出来，并构造成图片

                        FileOutputStream out = new FileOutputStream(file);
                        byte[] b = new byte[1024];
                        int len = 0;
                        while((len = is.read(b)) != -1)
                        {
                            out.write(b, 0, len);
                        }
                        out.flush();
                        out.close();
                        msg1=handler0.obtainMessage();
                        msg1.arg1 = 258;
                        msg1.obj = file;
                        handler0.sendMessage(msg1);
                    }
                    else
                    {
                        String s = "请求图片时，返回："+repcode;
                        new MessageToUi().send(23,"exception",s,handler0);
                    }
                }
            }
            catch (Exception e)
            {
                e.printStackTrace();
                new MessageToUi().send(23,"exception",e.toString(),handler0);
                return;
            }*/

        }
    }



    public class httpsyncStyleNumInfo extends Thread {
        public Context context0 = null;
        public Handler handler0 = null;
        public String Url = null;


        public httpsyncStyleNumInfo(Handler handlerin, Context contextin, String url) {
            handler0 = handlerin;
            context0 = contextin;
            Url = url;

        }

        public void run()
        {
            String result = "";
            String imageUrl = "";
            HttpClient httpCient = new DefaultHttpClient();
            try
            {
                HttpGet httpGet = new HttpGet(Url);
                httpCient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,3000);//连接时间
                httpCient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,2000);//数据传输时间
                int code = -1;

                Log.i(TAG, Url);
                HttpResponse response = httpCient.execute(httpGet);
                code = response.getStatusLine().getStatusCode();
                Log.i(TAG, "get orderinfo reponse code: "+Integer.toString(code));
                if (response.getStatusLine().getStatusCode() == 200)
                {
                    HttpEntity entity = response.getEntity();
                    result = EntityUtils.toString(entity, HTTP.UTF_8);
                    Log.i(TAG, result);
                }
                else
                {
                    String s = "服务端返回："+code;
                    new MessageToUi().send(23,"exception",s,handler0);
                    return;
                }
            }
            catch (Exception e)
            {
                lastCache = "null";//网络错误，需要重新刷新赋值缓存
                Log.e(TAG, "HTTP request err......");
                e.printStackTrace();
                new MessageToUi().send(23,"exception",e.toString(),handler0);
                return;
            }
            try
            {
                JSONObject jsonObj = new JSONObject(result);
                if (jsonObj == null)
                    return;
                else
                {
                    if(jsonObj.has("error")==true)
                    {
                        JSONObject error = jsonObj.optJSONObject("error");
                        if (error != null)
                        {
                            String message ="获取款式详情信息错误：" +error.optString("message");
                            new MessageToUi().send(23,"exception",message,handler0);
                            return;
                        }
                    }
                    else
                    {
                        if(jsonObj.has("data")==true)
                        {
                            JSONArray data = jsonObj.optJSONArray("data");
                            if(data!=null)
                            {
                                Config.styeNumInfo.sizeList.clear();
                                int size = data.length();
                                for(int i= 0;i< size;i++)
                                {
                                    if(data.isNull(i)==false)
                                    {
                                        JSONArray array0 = data.optJSONArray(i);
                                        if(array0!=null)
                                        {
                                            StyeNumInfo.node tmp = new StyeNumInfo().new node();
                                            int len = array0.length();
                                            for(int k = 0;k<len;k++)
                                            {
                                                tmp.s.add(array0.optString(k));
                                            }
                                            Config.styeNumInfo.sizeList.add(tmp);
                                        }
                                    }
                                }
                            }
                            new MessageToUi().send(199,"info","styNumInfo",handler0);
                        }
                    }
                }
            }
            catch (JSONException e)
            {
                e.printStackTrace();
                new MessageToUi().send(23,"exception",e.toString(),handler0);
            }
        }
    }
}







